package cn.edu.ctbu.myfirstweb.configurer;

import cn.edu.ctbu.myfirstweb.interceptor.CookieAndSessionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private CookieAndSessionInterceptor cookieAndSessionInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(cookieAndSessionInterceptor)
                //拦截哪些内容，所有请求都会被拦截，包括静态资源
                .addPathPatterns("/**")
                //放行哪些内容
                .excludePathPatterns(
                        "/",
                        "/**/login",
                        "/**/result",
                        "/**/*.html",
                        "/**/*.js",
                        "/**/*.css",
                        "/**/*.jpg",
                        "/**/*.map",
                        "/**/*.png"
                );

    }

}
